//引入api中需要用的请求函数
import {reqCategoryList,reqBannerList,reqFloorList} from '@/api/'


const state = {
  //仓库home存储数据的地方, 用来存储商品分类的地方
  categoryList:[],
  bannerList:[],
  floorList:[],
};


const mutations = {
  //state:当前仓库state的数据  categoryList:commit提交过来的数据
  GETCATEGORYLIST(state,categoryList) {
    state.categoryList= categoryList;
  },
  BANNERLIST(state,bannerList){
    state.bannerList = bannerList;
  },
  FLOORLIST(state,floorList) {
    state.floorList = floorList;
  }
};
//actions书写逻辑 if 书写异步
const actions = {
  //actions中的第一个参数context 第二个参数:组件派发actions的时候携带参数payload
  async getReqCategoryList({commit,dispatch,getters,state}) {
    //获取商品数据
     let result = await reqCategoryList();
     if(result.code == 200) {
      //提交到mutations 让mutations修改仓库里面state数据
       commit('GETCATEGORYLIST', result.data);
     }
     
  },
  //获取banner数据
  async bannerList({commit,dispatch,getters,state}) {
    let result = await reqBannerList();
    if(result.code == 200) {
      commit('BANNERLIST',result.data);
    }
  },
  //获取floor数据
  async floorList({commit,dispatch,getters,state}) {
    let result = await reqFloorList();
    if(result.code == 200) {
      commit('FLOORLIST',result.data);
    }
  }
  
};
//对外暴露小仓库
export default{
  state,
  mutations,
  actions
};
